/* ramOpen.c - ramOpen */

#include <xinu.h>
#include <stdlib.h>

/*------------------------------------------------------------------------
 *  ramOpen  -  creates a RAMDISK of the specificed size
 *------------------------------------------------------------------------
 */
devcall	ramOpen(
	struct dentry *devptr,	/* entry in device switch table	*/
	char *maxsize,
	char *extra
	)
{
	struct ramblk *ramptr;	/* pointer to ramtab entry	*/

	ramptr = &ramtab[ devptr->dvminor ];
	
	if(ramptr->opencount > 0) { /* check if ramdisk is open	*/
		return SYSERR;
	}
	else {
		ramptr->opencount ++;
	}

	ramptr->maxsize = atoi(maxsize);
	ramptr->fstblk = getmem(RMD_BLKSIZ * ramptr->maxsize);
	
	return OK;
}
